package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "资源(菜单)管理")
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @PostMapping("/list")
    @ApiOperation(value = "资源列表")
    public ResponseResult resourceList(@RequestBody ResourceDto resourceDto){
       List<ResourceVo> resourceVoList = resourceService.resourceList(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    @PostMapping("/tree")
    @ApiOperation(value = "资源树型")
    public ResponseResult resourceTree(@RequestBody ResourceDto resourceDto){
       TreeVo treeVo = resourceService.resourceTree(resourceDto);
        return ResponseResult.success(treeVo);
    }

    @PutMapping
    @ApiOperation(value = "资源添加")
    public ResponseResult createResource(@RequestBody ResourceDto resourceDto){
        resourceService.createResource(resourceDto);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation(value = "资源修改")
    public ResponseResult update(@RequestBody ResourceDto resourceDto){
        resourceService.update(resourceDto);
        return ResponseResult.success();
    }

    @PostMapping("/enable")
    @ApiOperation(value = "启用禁用")
    public  ResponseResult EnableDisable(@RequestBody ResourceDto resourceDto){
        resourceService.enableDisable(resourceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{resourceNo}")
    @ApiOperation(value = "删除菜单")
    public ResponseResult delete(@PathVariable String resourceNo){
        resourceService.delete(resourceNo);
        return ResponseResult.success();
    }
}
